******************************************************************************************
* Do-file name:	cr_real_wages_ado.do    
* Task:         create wage including censoring limits, create real wages    
* Last change:  30.04.2017  
******************************************************************************************


// used censoring limits and cpi are based on iab data.

******************************************************************************************
*** create wage including censoring limits
******************************************************************************************

gen tag_entg_cens = tag_entg 
label variable tag_entg_cens "avg. daily wage (in euro, includ. censoring limits, based on tag_entg)"

*** lower bound		// conservative censoring limit, a bit higher than IAB (i.e., always rounding to the next higher integer)
replace tag_entg_cens = 7  if tag_entg_cens <= 7 & year == 1980
replace tag_entg_cens = 7  if tag_entg_cens <= 7 & year == 1981
replace tag_entg_cens = 7  if tag_entg_cens <= 7 & year == 1982
replace tag_entg_cens = 7  if tag_entg_cens <= 7 & year == 1983
replace tag_entg_cens = 7  if tag_entg_cens <= 7 & year == 1984
replace tag_entg_cens = 7  if tag_entg_cens <= 7 & year == 1985
replace tag_entg_cens = 7  if tag_entg_cens <= 7 & year == 1986
replace tag_entg_cens = 8  if tag_entg_cens <= 8 & year == 1987
replace tag_entg_cens = 8  if tag_entg_cens <= 8 & year == 1988
replace tag_entg_cens = 8  if tag_entg_cens <= 8 & year == 1989
replace tag_entg_cens = 8  if tag_entg_cens <= 8 & year == 1990
replace tag_entg_cens = 9  if tag_entg_cens <= 9 & year == 1991

replace tag_entg_cens = 9  if tag_entg_cens <= 9  & year == 1992 & ost == 0
replace tag_entg_cens = 6  if tag_entg_cens <= 6  & year == 1992 & ost == 1
replace tag_entg_cens = 9  if tag_entg_cens <= 9  & year == 1993 & ost == 0
replace tag_entg_cens = 7  if tag_entg_cens <= 7  & year == 1993 & ost == 1
replace tag_entg_cens = 10 if tag_entg_cens <= 10 & year == 1994 & ost == 0
replace tag_entg_cens = 8  if tag_entg_cens <= 8  & year == 1994 & ost == 1
replace tag_entg_cens = 10 if tag_entg_cens <= 10 & year == 1995 & ost == 0
replace tag_entg_cens = 8  if tag_entg_cens <= 8  & year == 1995 & ost == 1
replace tag_entg_cens = 10 if tag_entg_cens <= 10 & year == 1996 & ost == 0
replace tag_entg_cens = 9  if tag_entg_cens <= 9  & year == 1996 & ost == 1
replace tag_entg_cens = 11 if tag_entg_cens <= 11 & year == 1997 & ost == 0
replace tag_entg_cens = 9  if tag_entg_cens <= 9  & year == 1997 & ost == 1
replace tag_entg_cens = 11 if tag_entg_cens <= 11 & year == 1998 & ost == 0
replace tag_entg_cens = 9  if tag_entg_cens <= 9  & year == 1998 & ost == 1

replace tag_entg_cens = 11 if tag_entg_cens <= 11 & year == 1999
replace tag_entg_cens = 11 if tag_entg_cens <= 11 & year == 2000


*** create indicator for left censoring
gen left_cens = 0
replace left_cens = . if tag_entg_cens == .
label variable left_cens "wage is left censored (based on tag_entg_cens)"

replace left_cens = 1 if tag_entg_cens <= 7 & year == 1980
replace left_cens = 1 if tag_entg_cens <= 7 & year == 1981
replace left_cens = 1 if tag_entg_cens <= 7 & year == 1982
replace left_cens = 1 if tag_entg_cens <= 7 & year == 1983
replace left_cens = 1 if tag_entg_cens <= 7 & year == 1984
replace left_cens = 1 if tag_entg_cens <= 7 & year == 1985
replace left_cens = 1 if tag_entg_cens <= 7 & year == 1986
replace left_cens = 1 if tag_entg_cens <= 8 & year == 1987
replace left_cens = 1 if tag_entg_cens <= 8 & year == 1988
replace left_cens = 1 if tag_entg_cens <= 8 & year == 1989
replace left_cens = 1 if tag_entg_cens <= 8 & year == 1990
replace left_cens = 1 if tag_entg_cens <= 9 & year == 1991

replace left_cens = 1 if tag_entg_cens <= 9  & year == 1992 & ost == 0
replace left_cens = 1 if tag_entg_cens <= 6  & year == 1992 & ost == 1
replace left_cens = 1 if tag_entg_cens <= 9  & year == 1993 & ost == 0
replace left_cens = 1 if tag_entg_cens <= 7  & year == 1993 & ost == 1
replace left_cens = 1 if tag_entg_cens <= 10 & year == 1994 & ost == 0
replace left_cens = 1 if tag_entg_cens <= 8  & year == 1994 & ost == 1
replace left_cens = 1 if tag_entg_cens <= 10 & year == 1995 & ost == 0
replace left_cens = 1 if tag_entg_cens <= 8  & year == 1995 & ost == 1
replace left_cens = 1 if tag_entg_cens <= 10 & year == 1996 & ost == 0
replace left_cens = 1 if tag_entg_cens <= 9  & year == 1996 & ost == 1
replace left_cens = 1 if tag_entg_cens <= 11 & year == 1997 & ost == 0
replace left_cens = 1 if tag_entg_cens <= 9  & year == 1997 & ost == 1
replace left_cens = 1 if tag_entg_cens <= 11 & year == 1998 & ost == 0
replace left_cens = 1 if tag_entg_cens <= 9  & year == 1998 & ost == 1

replace left_cens = 1 if tag_entg_cens <= 11 & year == 1999
replace left_cens = 1 if tag_entg_cens <= 11 & year == 2000


*** upper bound	 
replace tag_entg_cens = 68  if tag_entg_cens >= 68  & year == 1980 & tag_entg_cens != .
replace tag_entg_cens = 72  if tag_entg_cens >= 72  & year == 1981 & tag_entg_cens != .
replace tag_entg_cens = 76  if tag_entg_cens >= 76  & year == 1982 & tag_entg_cens != .
replace tag_entg_cens = 80  if tag_entg_cens >= 80  & year == 1983 & tag_entg_cens != .
replace tag_entg_cens = 85  if tag_entg_cens >= 85  & year == 1984 & tag_entg_cens != .
replace tag_entg_cens = 89  if tag_entg_cens >= 89  & year == 1985 & tag_entg_cens != .
replace tag_entg_cens = 92  if tag_entg_cens >= 92  & year == 1986 & tag_entg_cens != .
replace tag_entg_cens = 93  if tag_entg_cens >= 93  & year == 1987 & tag_entg_cens != .
replace tag_entg_cens = 97  if tag_entg_cens >= 97  & year == 1988 & tag_entg_cens != .
replace tag_entg_cens = 99  if tag_entg_cens >= 99  & year == 1989 & tag_entg_cens != .
replace tag_entg_cens = 103 if tag_entg_cens >= 103 & year == 1990 & tag_entg_cens != .
replace tag_entg_cens = 107 if tag_entg_cens >= 107 & year == 1991 & tag_entg_cens != .

replace tag_entg_cens = 111 if tag_entg_cens >= 111 & year == 1992 & ost == 0 & tag_entg_cens != .
replace tag_entg_cens = 78  if tag_entg_cens >= 78  & year == 1992 & ost == 1 & tag_entg_cens != .
replace tag_entg_cens = 119 if tag_entg_cens >= 119 & year == 1993 & ost == 0 & tag_entg_cens != .
replace tag_entg_cens = 87  if tag_entg_cens >= 87  & year == 1993 & ost == 1 & tag_entg_cens != .
replace tag_entg_cens = 125 if tag_entg_cens >= 125 & year == 1994 & ost == 0 & tag_entg_cens != .
replace tag_entg_cens = 97  if tag_entg_cens >= 97  & year == 1994 & ost == 1 & tag_entg_cens != .
replace tag_entg_cens = 129 if tag_entg_cens >= 129 & year == 1995 & ost == 0 & tag_entg_cens != .
replace tag_entg_cens = 105 if tag_entg_cens >= 105 & year == 1995 & ost == 1 & tag_entg_cens != .
replace tag_entg_cens = 132 if tag_entg_cens >= 132 & year == 1996 & ost == 0 & tag_entg_cens != .
replace tag_entg_cens = 111 if tag_entg_cens >= 111 & year == 1996 & ost == 1 & tag_entg_cens != .
replace tag_entg_cens = 135 if tag_entg_cens >= 135 & year == 1997 & ost == 0 & tag_entg_cens != .
replace tag_entg_cens = 117 if tag_entg_cens >= 117 & year == 1997 & ost == 1 & tag_entg_cens != .
replace tag_entg_cens = 139 if tag_entg_cens >= 139 & year == 1998 & ost == 0 & tag_entg_cens != .
replace tag_entg_cens = 115 if tag_entg_cens >= 115 & year == 1998 & ost == 1 & tag_entg_cens != .
replace tag_entg_cens = 140 if tag_entg_cens >= 140 & year == 1999 & ost == 0 & tag_entg_cens != .
replace tag_entg_cens = 119 if tag_entg_cens >= 119 & year == 1999 & ost == 1 & tag_entg_cens != .
replace tag_entg_cens = 142 if tag_entg_cens >= 142 & year == 2000 & ost == 0 & tag_entg_cens != .
replace tag_entg_cens = 117 if tag_entg_cens >= 117 & year == 2000 & ost == 1 & tag_entg_cens != .


*** create indicator for right censoring
gen right_cens = 0
replace right_cens = . if tag_entg_cens == .
label variable right_cens "wage is right censored (based on tag_entg_cens)"

replace right_cens = 1  if tag_entg_cens >= 68  & year == 1980 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 72  & year == 1981 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 76  & year == 1982 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 80  & year == 1983 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 85  & year == 1984 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 89  & year == 1985 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 92  & year == 1986 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 93  & year == 1987 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 97  & year == 1988 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 99  & year == 1989 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 103 & year == 1990 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 107 & year == 1991 & tag_entg_cens != .

replace right_cens = 1  if tag_entg_cens >= 111 & year == 1992 & ost == 0 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 78  & year == 1992 & ost == 1 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 119 & year == 1993 & ost == 0 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 87  & year == 1993 & ost == 1 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 125 & year == 1994 & ost == 0 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 97  & year == 1994 & ost == 1 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 129 & year == 1995 & ost == 0 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 105 & year == 1995 & ost == 1 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 132 & year == 1996 & ost == 0 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 111 & year == 1996 & ost == 1 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 135 & year == 1997 & ost == 0 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 117 & year == 1997 & ost == 1 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 139 & year == 1998 & ost == 0 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 115 & year == 1998 & ost == 1 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 140 & year == 1999 & ost == 0 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 119 & year == 1999 & ost == 1 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 142 & year == 2000 & ost == 0 & tag_entg_cens != .
replace right_cens = 1  if tag_entg_cens >= 117 & year == 2000 & ost == 1 & tag_entg_cens != .


******************************************************************************************
*** create real wages (non-imputed, based on tag_entg & tag_entg_cens)
******************************************************************************************

/// Real wages in euro at constant prices 1995.
/// CPI for All Private Households to deflate current wages between. 1995=100. 

foreach var of varlist tag_entg tag_entg_cens {
gen real_`var' = `var'
replace real_`var' = `var' / (0.664) if year == 1980 
replace real_`var' = `var' / (0.706) if year == 1981 
replace real_`var' = `var' / (0.743) if year == 1982 
replace real_`var' = `var' / (0.767) if year == 1983 
replace real_`var' = `var' / (0.786) if year == 1984 
replace real_`var' = `var' / (0.802) if year == 1985 
replace real_`var' = `var' / (0.801) if year == 1986 
replace real_`var' = `var' / (0.803) if year == 1987 
replace real_`var' = `var' / (0.813) if year == 1988 
replace real_`var' = `var' / (0.836) if year == 1989 
replace real_`var' = `var' / (0.858) if year == 1990 
replace real_`var' = `var' / (0.890) if year == 1991  
replace real_`var' = `var' / (0.925) if year == 1992  
replace real_`var' = `var' / (0.958) if year == 1993 
replace real_`var' = `var' / (0.984) if year == 1994 
replace real_`var' = `var' / (1.0)   if year == 1995 
replace real_`var' = `var' / (1.013) if year == 1996 
replace real_`var' = `var' / (1.032) if year == 1997  
replace real_`var' = `var' / (1.041) if year == 1998 
replace real_`var' = `var' / (1.048) if year == 1999 
replace real_`var' = `var' / (1.063) if year == 2000
	}
label var real_tag_entg "real average daily wage (in euro, based on tag_entg)"
label var real_tag_entg_cens "real avg. daily wage (in euro, includ. censoring limits, based on tag_entg_cens)"
